﻿using FastCloud.Base.Config;
using FastCloud.Base.Desgin;
using FastCloud.ORG.Entity;
using FastIOC.Attribute;
using FastUtil.Convert;
using FastUtil.Data;
using System;
using System.Collections.Generic;
using System.Text;

namespace FastCloud.ORG.DB
{
    public class DB_Tenant : BaseDBML<Frame_Tenant>
    {

        public override void Insert(Frame_Tenant Entity)
        {
            if (string.IsNullOrEmpty(Entity.TenantID))
            {
                Entity.TenantID = GenerateUtil.GenerateRowGuid();
            }
            Entity.AddDate = DateTime.Now;
            base.Insert(Entity);
        }

        public bool ExistTenant(string TenantName)
        {
            Add2Parameter("TenantName", TenantName);
            int count = SelectCount("TenantName=@TenantName");
            return count > 0;
        }

        public bool ExistTenant(string TenantID, string TenantName)
        {
            Add2Parameter("TenantName", TenantName);
            Add2Parameter("TenantID", TenantID);
            int count = SelectCount("TenantName=@TenantName and TenantID!=@TenantID");
            return count > 0;
        }
    }
}
